Skip to content

Conversation

elnosh
Copy link
Contributor

@elnosh elnosh commented Oct 3, 2025

Resolves #4048

Previously `should_broadcast_holder_commitment_txn` would FC a
channel if an outbound HTLC that hasn't been resolved was
`LATENCY_GRACE_PERIOD_BLOCKS` past expiry. For outgoing payments
that won't have an inbound HTLC, block time to allow before we
FC could be higher since we are not in a race to claim an
inbound HTLC. Here we use 2016 blocks which is roughly 2 weeks.
For cases in which a node has been offline for a while, this could
help to fail the HTLC on reconnection instead of causing a FC.

This would give often-offline nodes roughly 2 weeks to come back online to try salvage channel
and not FC in case they had a pending payment that ultimately failed.

I'm not entirely sure if this is the right solution. This causes some tests that expect force-closures after LATENCY_GRACE_PERIOD_BLOCKS for outgoing payments to fail. Opening in draft just to see if I can get review on if this is ok to delay FC for outgoing payments where we don't have an inbound HTLC to claim.

Previously `should_broadcast_holder_commitment_txn` would FC a
channel if an outbound HTLC that hasn't been resolved was
`LATENCY_GRACE_PERIOD_BLOCKS` past expiry. For outgoing payments
that won't have an inbound HTLC, block time to allow before we
FC could be higher since we are not in a race to claim an
inbound HTLC. Here we use 2016 blocks which is roughly 2 weeks.
For cases in which a node has been offline for a while, this could
help to fail the HTLC on reconnection instead of causing a FC.
@ldk-reviews-bot
Copy link

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

}

#[test]
fn test_no_fc_outgoing_payment() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to test the async payment version. It should be easy to copy the held_htlc_timeout test and add a disconnect + connect extra blocks until the HTLC fully times out, and ensure the HTLC is failed back on disconnect without FC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will add 👍

true
};
if (htlc_outbound && has_incoming && htlc.0.cltv_expiry + LATENCY_GRACE_PERIOD_BLOCKS <= height) ||
(htlc_outbound && !has_incoming && htlc.0.cltv_expiry + 2016 <= height) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think per the issue, we shouldn't FC at all for these timed out outbound payments. I can't really see a downside to doing that since the user can FC manually or contact their counterparty out-of-band, though I could be missing something. It should be really rare/weird for the counterparty to not just fail the HTLC back on reconnect anyway.

Asked @wpaulino offline and he seemed to confirm this approach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will remove the arbitrary 2016 I added. Yeah I thought about not FC at all but wasn't sure in case something weird happens and counterparty never fails it back and could end up with the HTLC stuck there. But yeah, it can FC manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Don't FC during startup chain relay if we might be able to salvage the channel by connecting to a peer
3 participants